package b3.widget.home
{
	import flash.display.Sprite;
	
	public class SpriteSetBar extends Sprite
	{
		private var sprites:Object;
		private var invisibleSprites:Object;
		private var gapY:Number;
		
		public function SpriteSetBar(gapY:Number = 35)
		{
			sprites = new Object();
			invisibleSprites = new Object();
			this.gapY = gapY;
		}
		
		public function setSprite(index:int, sprite:Sprite):void
		{
			if(sprites[index] == null)
			{
				sprites[index] = sprite;
			}
			else
			{
				var oldSprite:Sprite = sprites[index];
				this.removeChild(oldSprite);
				invisibleSprites[index] = oldSprite;
				delete sprites[index];
				sprites[index] = sprite;
			}
			sprite.x = calX(index);
			sprite.y = calY(index);
			this.addChild(sprite);
		}
		
		public function getVisibleSprite(index:int):Sprite
		{
			return sprites[index];
		}

		public function getInvisibleSprite(index:int):Sprite
		{
			return invisibleSprites[index];
		}
		
		public function setInvisibleSprite(index:int, sprite:Sprite):void
		{
			invisibleSprites[index] = sprite;
		}
		
		public function exchangeSprite(index:int):void
		{
			if (invisibleSprites[index] != null)
				setSprite(index, invisibleSprites[index]);
		}
		
		private function calX(index:int):Number
		{
			return 0;
		}
		
		private function calY(index:int):Number
		{
			return index * gapY;
		}
	}
}